package com.front.managementfront.banner.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.front.managementfront.banner.entity.HktsBanner;
import com.front.managementfront.banner.mapper.HktsBannerMapper;
import com.front.managementfront.banner.service.IHktsBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hml
 * @since 2021-04-22
 */
@Service
@Transactional
public class HktsBannerServiceImpl extends ServiceImpl<HktsBannerMapper, HktsBanner> implements IHktsBannerService {


    @Autowired
    private HktsBannerMapper hktsBannerMapper;

    @Override
    public IPage<HktsBanner> selectPage(Page<HktsBanner> page, HktsBanner hktsBanner) {
        QueryWrapper<HktsBanner> query = Wrappers.query();
        QueryWrapper<HktsBanner> entityWrapper = getEntityWrapper(query, hktsBanner);
        return hktsBannerMapper.selectPage(page, entityWrapper);
    }


    @Override
    public List<HktsBanner> selectList(HktsBanner hktsBanner) {
        QueryWrapper<HktsBanner> query = Wrappers.query();
        QueryWrapper<HktsBanner> entityWrapper = getEntityWrapper(query, hktsBanner);
        return hktsBannerMapper.selectList(entityWrapper);
    }

    /**
     * 公共查询条件
     *
     * @param entityWrapper
     * @return
     */
    public QueryWrapper<HktsBanner> getEntityWrapper(QueryWrapper<HktsBanner> entityWrapper, HktsBanner hktsBanner) {
        //条件拼接
        if (StringUtils.isNotBlank(hktsBanner.getCreateBy())) {
            entityWrapper.like(HktsBanner.CREATE_BY, hktsBanner.getCreateBy());
        }
                /*if(StringUtils.isNotBlank(hktsBanner.getCreateTime())){
                entityWrapper.like(HktsBanner.CREATE_TIME,hktsBanner.getCreateTime());
                }
                if(StringUtils.isNotBlank(hktsBanner.getDelFlag())){
                entityWrapper.like(HktsBanner.DEL_FLAG,hktsBanner.getDelFlag());
                }*/
        if (StringUtils.isNotBlank(hktsBanner.getUpdateBy())) {
            entityWrapper.like(HktsBanner.UPDATE_BY, hktsBanner.getUpdateBy());
        }
                /*if(StringUtils.isNotBlank(hktsBanner.getUpdateTime())){
                entityWrapper.like(HktsBanner.UPDATE_TIME,hktsBanner.getUpdateTime());
                }*/
        if (StringUtils.isNotBlank(hktsBanner.getBannerLink())) {
            entityWrapper.like(HktsBanner.BANNER_LINK, hktsBanner.getBannerLink());
        }
                /*if(StringUtils.isNotBlank(hktsBanner.getBannerOrder())){
                entityWrapper.like(HktsBanner.BANNER_ORDER,hktsBanner.getBannerOrder());
                }*/
        if (StringUtils.isNotBlank(hktsBanner.getBannerPath())) {
            entityWrapper.like(HktsBanner.BANNER_PATH, hktsBanner.getBannerPath());
        }
        if (StringUtils.isNotBlank(hktsBanner.getIsShow())) {
            entityWrapper.like(HktsBanner.IS_SHOW, hktsBanner.getIsShow());
        }
        return entityWrapper;
    }
}
